<template>
  <div class="carry-detail">
    <PageTemplate>
      <div slot="content">
        <TitleBack :title="title"></TitleBack>
        <!-- 基本信息 -->
        <PageEditCollapse :is-search="false" :default-collapse="true">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 200px;">{{$t('cm.baseinfo')}}</div>
          </div>
          <div>
            <el-form
              :model="projectInfo"
              label-position="right"
              label-width="150px"
              class="page-edit-colllapse-form"
              ref="projectInfo"
            >
              <el-row>
                <el-col :span="8">
                  <el-form-item label="项目编码" prop="projectCode" required>
                    <span>{{projectInfo.projectCode}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="项目名称" prop="projectName" required>
                    <span>{{projectInfo.projectName}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="客户名称" prop="marketCustomerName">
                    <span>{{projectInfo.marketCustomerName}}</span>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row>
                <el-col :span="8">
                  <el-form-item label="合同编码" prop="contractCode" required>
                    <span>{{projectInfo.contractCode}}</span>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="合同名称" prop="contractName" required>
                    <span>{{projectInfo.contractName}}</span>
                  </el-form-item>
                </el-col>
              </el-row>
            </el-form>
          </div>
        </PageEditCollapse>
        <!-- 组建实施团队 -->
        <PageEditCollapse 
          :is-search="false" 
          :default-collapse="true"
          v-if="showModules[1]">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 400px;">组建实施团队</div>
          </div>
          <BlockLookEditToggle 
            ref="pitBlockToggle"
            :isDefaultActive="curEditIndex==1"
            v-loading="projectImplementationTeamLoading"
            :activeMouse="type==='edit'"
            @editClick="projectImplementationTeamEditClick"
            @mouseleave="projectImplementationTeamMouseleaveHandle"
            @cancelClick="projectImplementationTeamCancelClick"
            @saveClick="projectImplementationTeamSaveClick">
            <div slot="content">
              <el-form
                :model="projectImplementationTeam"
                label-position="right"
                label-width="150px"
                class="page-edit-colllapse-form"
                ref="projectImplementationTeam">
                <el-row>
                  <el-col :span='12'>
                      <el-form-item label="项目开始日期" prop="projectDate" :rules="rules">
                        <span v-if="!projectImplementationTeamEdit">{{projectImplementationTeam.projectDate}}</span>
                        <el-date-picker 
                          v-else
                          v-model="projectImplementationTeam.projectDate" 
                          type="date" 
                          value-format="yyyy-MM-dd"
                          placeholder="选择日期">
                        </el-date-picker>
                      </el-form-item>
                  </el-col>
                  <el-col :span="12">
                      <el-form-item label="项目经理" prop="projectManagerName" :rules="rules">
                        <span v-if="!projectImplementationTeamEdit">{{projectImplementationTeam.projectManagerName}}</span>
                        <PersonSelect 
                          v-else
                          :value="projectImplementationTeam.projectManagerName" 
                          v-bind:multiple="false" 
                          ref="projectManagerName"
                          size="">
                        </PersonSelect>
                      </el-form-item>
                    </el-col>
                   </el-row>
                    <el-row>
                    <el-col :span="12">
                        <el-form-item label="商务经理" prop="businessManagerName" :rules="rules">
                        <span v-if="!projectImplementationTeamEdit">{{projectImplementationTeam.businessManagerName}}</span>
                        <PersonSelect 
                          v-else
                          :value="projectImplementationTeam.businessManagerName" 
                          v-bind:multiple="false" 
                          ref="businessManagerName"
                          size="">
                        </PersonSelect>
                      </el-form-item>
                    </el-col>
                   <el-col :span="12">
                        <el-form-item label="项目成员" prop="projectImplementationTeamMembersStr" :rules="rules">
                        <span v-if="!projectImplementationTeamEdit">{{projectImplementationTeam.projectImplementationTeamMembersStr}}</span>
                        <PersonSelect 
                          v-else
                          :value="projectImplementationTeam.projectImplementationTeamMembersStr" 
                          v-bind:multiple="true"
                          ref="projectImplementationTeamMembers" 
                          size="">
                        </PersonSelect>
                      </el-form-item>
                    </el-col>
                </el-row>
              </el-form>
            </div>
          </BlockLookEditToggle>
          <div>
          </div>
        </PageEditCollapse>
        <!-- 项目属性认定 -->
        <PageEditCollapse 
          :is-search="false" 
          :default-collapse="true"
          v-if="showModules[2]">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 400px;">项目属性认定</div>
          </div>
          <BlockLookEditToggle 
            ref="pisBlockToggle"
            :isDefaultActive="curEditIndex==2"
            v-loading="projectImplementationShuxingLoading"
            :activeMouse="type==='edit'"
            @editClick="projectImplementationShuxingEditClick"
            @mouseleave="projectImplementationShuxingMouseleaveHandle"
            @cancelClick="projectImplementationShuxingCancelClick"
            @saveClick="projectImplementationShuxingSaveClick">
            <div slot="content">
              <el-form
                :model="projectImplementationShuxing"
                label-position="right"
                label-width="160px"
                class="page-edit-colllapse-form"
                ref="projectImplementationShuxing">
                   <el-row>
                      <el-col :span='12'>
                        <el-form-item label="项目属性认定申请表" prop="xmsxrdFileid" :rules="rules">
                          <span v-if="!projectImplementationShuxingEdit">{{projectImplementationShuxing.xmsxrdFileName}}</span>
                          <FileUploadCommon 
                            v-else 
                            @uploadSuccess="uploadSuccess" 
                            @uploadRemove="uploadRemove" 
                            fileKey="xmsxrdFileid"
                            :fileList="projectImplementationShuxingXmsxrdFileList"
                            :limit="1">
                           </FileUploadCommon>
                        </el-form-item>
                      </el-col>
                  </el-row>
              </el-form>
            </div>
          </BlockLookEditToggle>
          <div>
          </div>
        </PageEditCollapse>
         <!-- 实施阶段WBS及预算申请 -->
        <PageEditCollapse 
          :is-search="false" 
          :default-collapse="true"
          v-if="showModules[3]">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 400px;">实施阶段WBS及预算申请</div>
          </div>
          <BlockLookEditToggle 
            ref="piwBlockToggle"
            :isDefaultActive="curEditIndex==3"
            v-loading="projectImplementationWbsLoading"
            :activeMouse="type==='edit'"
            @editClick="projectImplementationWbsEditClick"
            @mouseleave="projectImplementationWbsMouseleaveHandle"
            @cancelClick="projectImplementationWbsCancelClick"
            @saveClick="projectImplementationWbsSaveClick">
            <div slot="content">
              <el-form
                :model="projectImplementationWbs"
                label-position="right"
                label-width="150px"
                class="page-edit-colllapse-form"
                ref="projectImplementationWbs">
                  <el-row>
                     <el-col :span='12'>
                         <el-form-item label="CBS编码" prop="cbsCode" :rules="rules">
                            <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.cbsCode}}</span>
                            <el-input v-else v-model="projectImplementationWbs.cbsCode"></el-input>
                         </el-form-item>
                     </el-col>
                     <el-col :span='12'>
                         <el-form-item label="CSB名称" prop="cbsName" :rules="rules">
                            <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.cbsName}}</span>
                            <el-input v-else v-model="projectImplementationWbs.cbsName"></el-input>
                         </el-form-item>
                     </el-col>
                     <el-col :span='12'>
                         <el-form-item label="负责人" prop="leadingmanName" :rules="rules">
                            <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.leadingmanName}}</span>
                            <PersonSelect 
                              v-else
                              :value="projectImplementationWbs.leadingmanName" 
                              v-bind:multiple="false" 
                              ref="projectImplementationWbsLeadingman"
                              size="">
                            </PersonSelect>
                         </el-form-item>
                     </el-col>
                      <el-col :span='12'>
                         <el-form-item label="预算总额" prop="depositAmount" :rules="priceRules">
                            <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.depositAmount}}</span>
                            <el-input v-else v-model="projectImplementationWbs.depositAmount" type="number"></el-input>
                         </el-form-item>
                      </el-col>
                      <el-col :span='12'>
                         <el-form-item label="币种" prop="currency">
                            <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.currencyLabel}}</span>
                            <el-select 
                              v-else
                              v-model="projectImplementationWbs.currency"  
                              placeholder="请选择">
                              <el-option 
                                v-for="item in currencyMap"
                                :key="item.dictText"
                                :label="item.dictText" 
                                :value="item.dictKey+''">
                              </el-option>
                            </el-select>
                         </el-form-item>
                      </el-col>
                      <el-col :span='12'>
                         <el-form-item label="预算类别" prop="budgetType">
                            <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.budgetTypeLabel}}</span>
                            <el-select 
                              v-else
                              v-model="projectImplementationWbs.budgetType"  
                              placeholder="请选择">
                              <el-option 
                                v-for="item in budgetTypeMap"
                                :key="item.dictText"
                                :label="item.dictText" 
                                :value="item.dictKey">
                              </el-option>
                            </el-select>
                         </el-form-item>
                      </el-col>
                      <el-col :span='12'>
                         <el-form-item label="跨类别转储" prop="transClassification">
                            <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.transClassification == 1 ? '是' : '否'}}</span>
                            <el-select  v-else v-model="projectImplementationWbs.transClassification"  placeholder="请选择" >
                              <el-option label="是" value="1"></el-option>
                              <el-option label="否" value="0"></el-option>
                            </el-select>
                         </el-form-item>
                      </el-col>
                      <el-col :span='12'>
                         <el-form-item label="支付转储" prop="payStorage">
                            <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.payStorage == 1 ? '是' : '否'}}</span>
                            <el-select  v-else v-model="projectImplementationWbs.payStorage"  placeholder="请选择" >
                              <el-option label="是" value="1"></el-option>
                              <el-option label="否" value="0"></el-option>
                            </el-select>
                         </el-form-item>
                      </el-col>
                      <el-col :span='12'>
                        <el-form-item label="合同" prop="htFileid" :rules="rules">
                          <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.htFileName}}</span>
                          <FileUploadCommon 
                            v-else 
                            @uploadSuccess="uploadSuccess"
                            @uploadRemove="uploadRemove"
                            fileKey="htFileid"
                            :fileList="projectImplementationWbsHtFileList"
                            :limit="1">
                          </FileUploadCommon>
                        </el-form-item>
                      </el-col>
                      <el-col :span='12'>
                        <el-form-item label="损益测算表" prop="sycsbFileid" :rules="rules">
                          <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.sycsbFileName}}</span>
                          <FileUploadCommon 
                            v-else 
                            @uploadSuccess="uploadSuccess"
                            @uploadRemove="uploadRemove" 
                            fileKey="sycsbFileid"
                            :fileList="projectImplementationWbsSycsbFileList"
                            :limit="1">
                          </FileUploadCommon>
                        </el-form-item>
                      </el-col>
                     <el-col :span='12'>
                        <el-form-item label="WBS申请表" prop="wbssqFileid" :rules="rules">
                          <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.wbssqFileName}}</span>
                          <FileUploadCommon 
                            v-else 
                            @uploadSuccess="uploadSuccess"
                            @uploadRemove="uploadRemove" 
                            fileKey="wbssqFileid"
                            :fileList="projectImplementationWbsWbssqFileList"
                            :limit="1">
                          </FileUploadCommon>
                        </el-form-item>
                      </el-col>
                      <el-col :span='12'>
                        <el-form-item label="预算申请表" prop="yssqFileid" :rules="rules">
                          <span v-if="!projectImplementationWbsEdit">{{projectImplementationWbs.yssqFileName}}</span>
                          <FileUploadCommon 
                            v-else 
                            @uploadSuccess="uploadSuccess"
                            @uploadRemove="uploadRemove" 
                            fileKey="yssqFileid"
                            :fileList="projectImplementationWbsYssqFileList"
                            :limit="1">
                          </FileUploadCommon>
                        </el-form-item>
                      </el-col>
                  </el-row>
              </el-form>
            </div>
          </BlockLookEditToggle>
          <div>
          </div>
        </PageEditCollapse>
        <!-- 项目执行 -->
        <PageEditCollapse 
          :is-search="false" 
          :default-collapse="true"
           v-if="showModules[4]">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 400px;">项目执行</div>
          </div>
          <BlockLookEditToggle 
            ref="piiBlockToggle"
            v-loading="projectImplementationImplementLoading"
            :isDefaultActive="curEditIndex==4"
            :activeMouse="type==='edit'"
            @editClick="projectImplementationImplementEditClick"
            @mouseleave="projectImplementationImplementMouseleaveHandle"
            @cancelClick="projectImplementationImplementCancelClick"
            @saveClick="projectImplementationImplementSaveClick">
            <div slot="content">
              <el-form
                :model="projectImplementationImplement"
                label-position="right"
                label-width="110px"
                class="page-edit-colllapse-form"
                ref="projectImplementationImplement">
                    <el-row>
                      <el-col :span="24">
                        <div v-if="projectImplementationImplementEdit || curEditIndex==4">
                          <el-button type="primary" @click="addImplementListHandle">
                            新增
                          </el-button>
                        </div>
                      </el-col>
                    </el-row>
                    <el-table
                      class="table"
                      border
                      ref="projectImplementationImplement"
                      :data="projectImplementationImplement.implementList"
                      tooltip-effect="dark"
                      style="width: 100%!important"
                      :show-overflow-tooltip="true"
                      @selection-change="handleSelectionChange"
                      :header-cell-style="{background:tableHeaderBGC}">
                      <el-table-column type="index" :label="$t('cm.no')" align="center" width="60"></el-table-column>
                      <el-table-column prop="date" label="日期" align="center"></el-table-column>
                      <el-table-column prop="progress" label="进展" align="center"></el-table-column>
                      <el-table-column 
                        prop="isddsk" label="是否达到收款条件" align="center"
                         :formatter="(row)=>{
                          let result = '';
                          switch (row.isddsk) {
                            case 0:
                              result = '否';
                              break;
                            case 1:
                              result = '是';
                              break;
                          }
                          return result;
                        }"></el-table-column>
                      <!-- <el-table-column prop="isddsk" label="是否达到收款条件" align="center"></el-table-column> -->
                      <el-table-column prop="yszsFileName" label="验收证书" align="center"></el-table-column>
                      <el-table-column prop="remarks" label="备注" align="center"></el-table-column>
                      <el-table-column v-if="type==='edit'&&projectImplementationImplementEdit" :label="$t('cm.operate')" prop="statussss" align="center" width="250">
                        <template slot-scope="scope">
                          <ListBtn :options="(scope.row.add || !(scope.row.isddsk-0))?btns:btns.concat(notify_business)" :row-data="Object.assign({},scope.row,{index:scope.$index})" @triggerListBtn="implementListHandleListBtn"></ListBtn>
                        </template>
                      </el-table-column>
                    </el-table>
                    <el-row>
                      <el-col :span='12'>
                        <el-form-item label="项目总结条件" prop="projectSummaryRequirement">
                            <span v-if="!projectImplementationImplementEdit">{{projectImplementationImplement.projectSummaryRequirement == 1 ? '达成' : '未达成'}}</span>
                            <el-radio-group v-else v-model="projectImplementationImplement.projectSummaryRequirement">
                              <el-radio label="1">达成</el-radio>
                              <el-radio label="0">未达成</el-radio>
                            </el-radio-group>
                         </el-form-item>
                      </el-col>
                    </el-row>
              </el-form>
            </div>
          </BlockLookEditToggle>
          <div>
          </div>
        </PageEditCollapse>
         <!-- 合同收款 -->
        <PageEditCollapse 
          :is-search="false" 
          :default-collapse="true"
           v-if="showModules[5]">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 400px;">合同收款</div>
          </div>
          <BlockLookEditToggle 
            ref="silBlockToggle"
            v-loading="summaryInfoListLoading"
            :isDefaultActive="curEditIndex==5"
            :activeMouse="type==='edit'"
            @editClick="summaryInfoListEditClick"
            @mouseleave="summaryInfoListMouseleaveHandle"
            @cancelClick="summaryInfoListCancelClick"
            @saveClick="summaryInfoListSaveClick">
            <div slot="content">
              <!-- <el-form
                :model="summaryInfoList"
                label-position="right"
                label-width="150px"
                class="page-edit-colllapse-form"
                ref="summaryInfoList"> -->
                  <el-row>
                      <el-col :span="24">
                        <div v-if="summaryInfoListEdit || curEditIndex==5">
                          <el-button type="primary" @click="addSummaryInfoListHandle">
                            新增
                          </el-button>
                        </div>
                      </el-col>
                    </el-row>
                     <el-table
                      class="table"
                      border
                      ref="summaryInfoList"
                      :data="summaryInfoList"
                      tooltip-effect="dark"
                      style="width: 100%"
                      :show-overflow-tooltip="true"
                      @selection-change="handleSelectionChange"
                      :header-cell-style="{background:tableHeaderBGC}"
                      show-summary
                      :summary-method="getSummaries">
                     <el-table-column type="index" :label="$t('cm.no')" align="center" width="60"></el-table-column>
                      <el-table-column prop="reconciliationTime" label="对账日期" align="center"></el-table-column>
                      <el-table-column prop="reconciliationJe" label="对账金额" align="center"></el-table-column>
                      <el-table-column prop="invoiceTime" label="开票日期" align="center"></el-table-column>
                      <el-table-column prop="invoiceJe" label="开票金额" align="center"></el-table-column>
                      <el-table-column prop="yszsFileName" label="验收证书" align="center"></el-table-column>
                      <el-table-column prop="zfsqhFileName" label="支付申请函" align="center"></el-table-column>
                      <el-table-column 
                        prop="isdz" label="是否已到帐" align="center"
                         :formatter="(row)=>{
                          let result = '';
                          switch (row.isdz) {
                            case 0:
                              result = '否';
                              break;
                            case 1:
                              result = '是';
                              break;
                          }
                          return result;
                        }"></el-table-column>
                      <el-table-column prop="dzyf" label="到账月份" align="center"></el-table-column>
                      <el-table-column prop="dzje" label="到账金额" align="center"></el-table-column>
                       <el-table-column v-if="type==='edit'&&summaryInfoListEdit" :label="$t('cm.operate')" prop="statussss" align="center" width="150">
                        <template slot-scope="scope">
                          <ListBtn :options="btns" :row-data="Object.assign({},scope.row,{index:scope.$index})" @triggerListBtn="summaryInfoListHandleListBtn"></ListBtn>
                        </template>
                      </el-table-column>
                    </el-table>
              <!-- </el-form> -->
            </div>
          </BlockLookEditToggle>
          <div>
          </div>
        </PageEditCollapse>
         <!-- 项目总结 -->
        <PageEditCollapse 
          :is-search="false" 
          :default-collapse="true"
           v-if="showModules[6]">
          <div slot="title" class="page-edit-colllapse-title">
            <div style="width: 400px;">项目总结</div>
          </div>
          <BlockLookEditToggle 
            ref="pisyBlockToggle"
            v-loading="projectImplementationSummaryLoading"
            :isDefaultActive="curEditIndex==6"
            :activeMouse="type==='edit'"
            @editClick="projectImplementationSummaryEditClick"
            @mouseleave="projectImplementationSummaryMouseleaveHandle"
            @cancelClick="projectImplementationSummaryCancelClick"
            @saveClick="projectImplementationSummarySaveClick">
            <div slot="content">
              <el-form
                :model="projectImplementationSummary"
                label-position="right"
                label-width="150px"
                class="page-edit-colllapse-form"
                ref="projectImplementationSummary">
                   <el-row>
                      <el-col :span='20'>
                         <el-form-item label="项目总结" prop="summary" :rules="rules">
                            <span v-if="!projectImplementationSummaryEdit">{{projectImplementationSummary.summary}}</span>
                            <el-input v-else v-model="projectImplementationSummary.summary" type="textarea" :rows="3"></el-input>
                         </el-form-item>
                      </el-col>
                   </el-row>
                   <el-row>
                      <el-col :span='12'>
                        <el-form-item label="总结报告" prop="summaryFileid" :rules="rules">
                          <span v-if="!projectImplementationSummaryEdit">{{projectImplementationSummary.summaryFileName}}</span>
                          <FileUploadCommon 
                            v-else 
                            @uploadSuccess="uploadSuccess"
                            @uploadRemove="uploadRemove" 
                            fileKey="summaryFileid"
                            :fileList="projectImplementationSummarySummaryFileList"
                            :limit="1">
                          </FileUploadCommon>
                        </el-form-item>
                      </el-col>
                  </el-row>
              </el-form>
            </div>
          </BlockLookEditToggle>
          <div>
          </div>
        </PageEditCollapse>
      </div>
    </PageTemplate>
    <!-- 项目执行新增弹窗 -->
    <el-dialog
      class="dialog"
      title="项目执行详情"
      :visible.sync="implementListDialogVisible"
      v-if="implementListDialogVisible"
      width="50%"
      :before-close="addImplementListCancel">
      <el-form
        :model="implementListForm"
        label-position="right"
        label-width="150px"
        class="page-edit-colllapse-form"
        ref="implementListForm">
        <el-row>
          <el-col :span="24">
            <el-form-item label="日期" prop="date" :rules="rules">
              <span v-if="implementListDialogObj.type == 'look'">{{implementListForm.date}}</span>
              <el-date-picker 
                v-else
                v-model="implementListForm.date" 
                type="date" 
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="进展" prop="progress" :rules="rules">
               <span v-if="implementListDialogObj.type == 'look'">{{implementListForm.progress}}</span>
              <el-input v-else v-model="implementListForm.progress"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="是否达到收款条件" prop="isddsk" :rules="rules">
              <span v-if="implementListDialogObj.type == 'look'">{{implementListForm.isddsk == 1 ?'是':'否'}}</span>
              <el-select v-else v-model="implementListForm.isddsk"  placeholder="请选择" >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="验收证书" prop="yszs" :rules="rules" style="width:70%">
              <span v-if="implementListDialogObj.type == 'look'">{{implementListForm.yszsFileName}}</span>
              <FileUploadCommon 
                ref="implementListFormYszs" 
                v-else 
                @uploadSuccess="uploadSuccess"
                @uploadRemove="uploadRemove"
                fileKey="implementListFormYszs" 
                :fileList="implementListFormYszsList"
                :limit="1">
              </FileUploadCommon>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <span v-if="implementListDialogObj.type == 'look'">{{implementListForm.remarks}}</span>
              <el-input v-else v-model="implementListForm.remarks" type="textarea" :rows="3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addImplementListCancel">取 消</el-button>
        <el-button v-if="implementListDialogObj.type != 'look'" type="primary" @click="addImplementListConfirm">确 定</el-button>
      </span>
    </el-dialog>

     <!-- 合同收款新增弹窗 -->
    <el-dialog
      class="dialog"
      title="合同详情"
      :visible.sync="summaryInfoListDialogVisible"
      v-if="summaryInfoListDialogVisible"
      :before-close="addSummaryInfoListCancel"
      width="50%">
      <el-form
        :model="summaryInfoListForm"
        label-position="right"
        label-width="150px"
        class="page-edit-colllapse-form"
        ref="summaryInfoListForm">
        <el-row>
          <el-col :span="24">
            <el-form-item label="对账日期" prop="reconciliationTime">
              <span v-if="summaryInfoListDialogObj.type == 'look'">{{summaryInfoListForm.reconciliationTime}}</span>
              <el-date-picker 
                v-else
                v-model="summaryInfoListForm.reconciliationTime" 
                type="date" 
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="对账金额" prop="reconciliationJe">
              <span v-if="summaryInfoListDialogObj.type == 'look'">{{summaryInfoListForm.reconciliationJe}}</span>
              <el-input v-else v-model="summaryInfoListForm.reconciliationJe" type="number"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开票日期" prop="invoiceTime" :rules="rules">
              <span v-if="summaryInfoListDialogObj.type == 'look'">{{summaryInfoListForm.invoiceTime}}</span>
              <el-date-picker 
                v-else
                v-model="summaryInfoListForm.invoiceTime" 
                type="date" 
                value-format="yyyy-MM-dd"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="开票金额" prop="invoiceJe" :rules="priceRules">
              <span v-if="summaryInfoListDialogObj.type == 'look'">{{summaryInfoListForm.invoiceJe}}</span>
              <el-input v-else v-model="summaryInfoListForm.invoiceJe" type="number"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="验收证书" prop="yszs" :rules="rules" style="width:70%">
              <span v-if="summaryInfoListDialogObj.type == 'look'">{{summaryInfoListForm.yszsFileName}}</span>
              <FileUploadCommon 
                ref="summaryInfoListFormYszs" 
                v-else 
                @uploadSuccess="uploadSuccess"
                @uploadRemove="uploadRemove" 
                fileKey="summaryInfoListFormYszs"
                :fileList="summaryInfoListFormYszsList"
                :limit="1">
              </FileUploadCommon>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="支付申请函" prop="zfsqh" :rules="rules" style="width:70%">
              <span v-if="summaryInfoListDialogObj.type == 'look'">{{summaryInfoListForm.zfsqhFileName}}</span>
              <FileUploadCommon 
                ref="summaryInfoListFormZfsqh" 
                v-else 
                @uploadSuccess="uploadSuccess"
                @uploadRemove="uploadRemove" 
                fileKey="summaryInfoListFormZfsqh"
                :fileList="summaryInfoListFormZfsqhList"
                :limit="1">
              </FileUploadCommon>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="是否已到帐" prop="isdz" :rules="rules">
              <span v-if="summaryInfoListDialogObj.type == 'look'">{{summaryInfoListForm.isdz == 1?"是":"否"}}</span>
              <el-select v-else v-model="summaryInfoListForm.isdz"  placeholder="请选择" >
                <el-option label="是" :value="1"></el-option>
                <el-option label="否" :value="0"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="到账月份" prop="dzyf" :rules="rules">
              <span v-if="summaryInfoListDialogObj.type == 'look'">{{summaryInfoListForm.dzyf}}</span>
              <el-date-picker 
                v-else
                v-model="summaryInfoListForm.dzyf" 
                type="date" 
                value-format="yyyy-MM"
                placeholder="选择日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="到账金额" prop="dzje" :rules="priceRules">
              <span v-if="summaryInfoListDialogObj.type == 'look'">{{summaryInfoListForm.dzje}}</span>
              <el-input v-else v-model="summaryInfoListForm.dzje" type="number"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addSummaryInfoListCancel">取 消</el-button>
        <el-button v-if="summaryInfoListDialogObj.type != 'look'" type="primary" @click="addSummaryInfoListConfirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { ALERT } from '@/utils/responseHandle'
import * as Constant from '@/utils/constant'
import PageTemplate from '@/components/common/PageTemplate'
import PageEditCollapse from '@/components/common/PageEditCollapse'
import ListBtn from '@/components/btn/ListBtn'
import TitleBack from '@/components/common/TitleBack'
import BlockLookEditToggle from '@/components/common/BlockLookEditToggle'
import Pagination from '@/mixins/Pagination'
import HasBtn from '@/mixins/HasBtn'
import { mapState } from 'vuex'
import {COMMON} from '@/utils/commonUtil'
import opr_management from '@/api/opr_management'
import sys_manage from '@/api/sys_manage'
import PersonSelect from '@/components/asc/PersonSelect'
import FileUploadCommon from '@/components/common/FileUploadCommon'
export default {
  components: {
    PageTemplate, 
    PageEditCollapse, 
    ListBtn,
    TitleBack, 
    BlockLookEditToggle,
    PersonSelect,
    FileUploadCommon
  },
  props: {
    // look：查看；edit：编辑
    type: {
      type: String,
      default: "look"
    },
  },
  data () {
    return {
      title:"项目实施详情",
      //当前默认显示为编辑状态的模块index
      curEditIndex:null,
      //接口返回的全部信息合集
      carryDetail:{},
      //模块是否显示
      showModules:[],
      //基本信息data
      projectInfo: {},
      //组建实施团队data
      projectImplementationTeam: {},
      //项目属性认定data
      projectImplementationShuxing:{},
      //实施阶段WBS及预算申请data
      projectImplementationWbs:{},
      ///项目执行data
      projectImplementationImplement:{
        projectSummaryRequirement: "0"
      },
      //合同收款data
      summaryInfoList:[],
      //项目总结data
      projectImplementationSummary:{},
      

      rules:[{ required: true, message: '必填项',trigger: 'blur'}],
      priceRules:[{ required: true, message: '必填,且必须是数字',trigger: 'blur'}],
      
     
      projectImplementationTeamEdit:false,//组建实施团队是否为编辑模式
      projectImplementationTeamLoading:false,//组建实施团队loading
      
      projectImplementationShuxingEdit:false,//项目评审是否为编辑模式
      projectImplementationShuxingLoading:false,//项目评审loading

      projectImplementationWbsEdit:false,//实施阶段WBS及预算申请是否为编辑模式
      projectImplementationWbsLoading:false,//实施阶段WBS及预算申请loading

      projectImplementationImplementEdit:false,//项目执行是否为编辑模式
      projectImplementationImplementLoading:false,//项目执行loading
      implementListDialogVisible:false,//新增项目执行弹窗是否显示
      implementListForm:{},////新增项目执行弹窗表单
      implementListDialogObj:{ //项目执行弹窗状态新增查看还是编辑
        type:"look",
        index:null,//若为编辑时需存入编辑的下标
      },

      summaryInfoListEdit:false,//合同收款是否为编辑模式
      summaryInfoListLoading:false,//合同收款loading
      summaryInfoListDialogVisible:false,//新增项目执行弹窗是否显示
      summaryInfoListForm:{},//新增合同收款弹窗表单
      summaryInfoListDialogObj:{//项目执行弹窗状态新增查看还是编辑
       type:"look",
       index:null,//若为编辑时需存入编辑的下标
      },
      projectImplementationSummaryEdit:false,//项目总结是否为编辑模式
      projectImplementationSummaryLoading:false,//项目总结loading


      btns: [
        {
          value: 'look',
          label: 'cm.look'
        },
        {
          value: 'edit',
          label: 'cm.edit'
        },
        {
          value: 'del',
          label: 'cm.delete'
        }
      ],
      notify_business: [
        {
          value: 'notify_business',
          label: 'opm.notify_business'
        }
      ],

      currencyMap:[],//币种字典
      budgetTypeMap:[],//预算类别字典

      projectImplementationShuxingXmsxrdFileList:[],
      projectImplementationWbsHtFileList:[],
      projectImplementationWbsSycsbFileList:[],
      projectImplementationWbsWbssqFileList:[],
      projectImplementationWbsYssqFileList:[],
      implementListFormYszsList:[],
      summaryInfoListFormYszsList:[],
      summaryInfoListFormZfsqhList:[],
      projectImplementationSummarySummaryFileList:[],
    }
  },
  mixins: [Pagination, HasBtn],
  watch: {
    carryDetail:{
      handler:function(val){
        const { 
          projectInfo,
          projectImplementationTeam,
          projectImplementationShuxing,
          projectImplementationWbs,
          projectImplementationImplement,
          summaryInfoList,
          projectImplementationSummary
        } = val;
        let showProjectInfo = projectInfo ? true :false;
        let showProjectImplementationTeam = projectImplementationTeam ? true :false;
        let showProjectImplementationShuxing = projectImplementationShuxing ? true :false;
        let showProjectImplementationWbs = projectImplementationWbs ? true :false;
        let showProjectImplementationImplement = projectImplementationImplement ? true :false;
        let showSummaryInfoList = summaryInfoList.length>0 ? true :false;
        let showProjectImplementationSummary = projectImplementationSummary ? true : false ;
        let arr = [showProjectInfo,showProjectImplementationTeam,showProjectImplementationShuxing,showProjectImplementationWbs,showProjectImplementationImplement,showSummaryInfoList,showProjectImplementationSummary];
        this.showModules = this.showModulesFn(arr,this.type);
        //判断合同收款跟项目总结显不显示
        if(projectImplementationImplement){
          const {projectSummaryRequirement,implementList} = projectImplementationImplement
          //当项目总结条件为未达成时，总结不显示
          if(projectSummaryRequirement==0){
            this.showModules[6] = false
          }
          //如项目执行有进展达到收款提交，则同时显示合同收款信息
          let bolArr = [];
          for( var item of implementList){
            bolArr.push(item.isddsk)
          }
          if(bolArr.indexOf(1) == -1){
            this.showModules[5] = false
          }
        }
        switch(this.curEditIndex){
            case 1 :
              this.projectImplementationTeamEdit = true;
              break; 
            case 2 :
              this.projectImplementationShuxingEdit = true;
              break; 
            case 3 :
              this.projectImplementationWbsEdit = true;
              break; 
            case 4 :
               this.projectImplementationImplementEdit = true;
              break; 
            case 5 :
              this.summaryInfoListEdit = true;
              break; 
            case 6 :
                this.projectImplementationSummaryEdit = true;
              break; 
        }
      },
      deep:true,
    }, 
    "projectImplementationTeam.members"(val) {
        if(val.length ==0 ) return;
        this.$set(this.projectImplementationTeam,'projectImplementationTeamMembersStr',COMMON.arrToStr(val,"peopleName"))
    }, 
  },
  computed: {
    ...mapState({
      tableHeaderBGC: state => state.common.tableHeaderBGC
    }),
    //组建实施团队项目成员字符串
    //  projectImplementationTeamMembersStr() {
    //   const { members } = this.projectImplementationTeam
    //   return COMMON.arrToStr(members,"peopleName");
    // },
  },
  created () {
    //获取全部字典
    this.getAllMap()
    //获取详情
    this.getInitData();
  },
  methods: {
    //获取全部字典
    getAllMap(){
      //获取币种字典
      this.sysDictLoadByPaging("run_currency",(result)=>{
          this.currencyMap = result.data
      })
      //获取预算类别字典
      this.sysDictLoadByPaging("run_budget_type",(result)=>{
          this.budgetTypeMap = result.data
      })

    },
    //获取字典接口
    sysDictLoadByPaging (key,callback) { 
      sys_manage.sysDictLoadByPaging({dictGroupKey: key}, result => {
        if (result.code === Constant.RT_SUCCESS) {
          callback(result)
        } else {
          ALERT.error(result.msg)
        }
      })
    },
   
    uploadSuccess(res,fileKey){
      if (!(res.data && res.data[0])) return;
      let { fileId,fileName,url }= res.data[0];
      let file = {name:fileName, url, id:fileId}
       switch(fileKey){
        case 'xmsxrdFileid'://项目属性认定-项目属性认定申请表
          this.projectImplementationShuxing.xmsxrdFileid = fileId;
          this.projectImplementationShuxingXmsxrdFileList.push(file);
          break;
        case 'htFileid':  //实施阶段WBS及预算申请-合同
          this.projectImplementationWbs.htFileid = fileId;
          this.projectImplementationWbsHtFileList.push(file);
          break;
        case 'sycsbFileid':  //承揽阶段WBS及预算申请-损益测算表
          this.projectImplementationWbs.sycsbFileid = fileId;
          this.projectImplementationWbsSycsbFileList.push(file);
          break;
        case 'wbssqFileid':  //承揽阶段WBS及预算申请-WBS申请表
          this.projectImplementationWbs.wbssqFileid = fileId;
          this.projectImplementationWbsWbssqFileList.push(file);
          break;
        case 'yssqFileid':  //承揽阶段WBS及预算申请-预算申请表
          this.projectImplementationWbs.yssqFileid = fileId;
          this.projectImplementationWbsYssqFileList.push(file);
          break;
        case 'implementListFormYszs':  //项目执行-验收证书
          this.implementListForm.yszs = fileId;
          this.implementListForm.yszsFileName = fileName;
          this.implementListFormYszsList.push(file);
          break;
        case 'summaryInfoListFormYszs':  //合同收款-验收证书
          this.summaryInfoListForm.yszs = fileId;
          this.summaryInfoListForm.yszsFileName = fileName;
          this.summaryInfoListFormYszsList.push(file);
          break;
        case 'summaryInfoListFormZfsqh':  //合同收款-支付申请函
          this.summaryInfoListForm.zfsqh = fileId;
          this.summaryInfoListForm.zfsqhFileName = fileName;
          this.summaryInfoListFormZfsqhList.push(file);
          break;
        case 'summaryFileid':  //合同总结-总结报告
          this.projectImplementationSummary.summaryFileid = fileId;
          this.projectImplementationSummarySummaryFileList.push(file);
          break;
       }
    },

    uploadRemove(fileList,fileKey){
       let resList = fileList.map(item => {
          return {
            name: item.name,
            url: item.url,
            id: item.fileId
          }
        })
        let fileId = resList.map(item=>item.id).join(",");
        let fileName = resList.map(item=>item.id).join(",");
       switch(fileKey){
        case 'xmsxrdFileid'://项目属性认定-项目属性认定申请表
          this.projectImplementationShuxingXmsxrdFileList = resList;
          this.projectImplementationShuxing.xmsxrdFileid = fileId;
          break;
        case 'htFileid':  //实施阶段WBS及预算申请-合同
          this.projectImplementationWbsHtFileList = resList;
          this.projectImplementationWbs.htFileid = fileId;
          break;
        case 'sycsbFileid':  //承揽阶段WBS及预算申请-损益测算表
          this.projectImplementationWbsSycsbFileList = resList;
          this.projectImplementationWbs.sycsbFileid = fileId;
          break;
        case 'wbssqFileid':  //承揽阶段WBS及预算申请-WBS申请表
          this.projectImplementationWbsWbssqFileList = resList;
          this.projectImplementationWbs.wbssqFileid = fileId;
          break;
        case 'yssqFileid':  //承揽阶段WBS及预算申请-预算申请表
          this.projectImplementationWbsYssqFileList = resList;
          this.projectImplementationWbs.yssqFileid = fileId;
          break;
        case 'implementListFormYszs':  //项目执行-验收证书
          this.implementListFormYszsList = resList;
          this.implementListForm.yszs = fileId;
          this.implementListForm.yszsFileName = fileName;
          break;
        case 'summaryInfoListFormYszs':  //合同收款-验收证书
          this.summaryInfoListFormYszsList = resList;
          this.summaryInfoListForm.yszs = fileId;
          this.summaryInfoListForm.yszsFileName = fileName;
          break;
        case 'summaryInfoListFormZfsqh':  //合同收款-支付申请函
          this.summaryInfoListFormZfsqhList = resList;
          this.summaryInfoListForm.zfsqh = fileId;
          this.summaryInfoListForm.zfsqhFileName = fileName;
          break;
        case 'summaryFileid':  //合同总结-总结报告
          this.projectImplementationSummarySummaryFileList = resList;
          this.projectImplementationSummary.summaryFileid = fileId;
          break;
       }
    },


    //获取详情
    getInitData(){
       opr_management.getProjectImplementationInfoById({
         id:this.$router.history.current.params.id
       }, result => {
         if (result.code === Constant.RT_SUCCESS) {
            const { 
             projectInfo,
             projectImplementationTeam,
             projectImplementationShuxing,
             projectImplementationWbs,
             projectImplementationImplement,
             summaryInfoList,
             projectImplementationSummary
            } = result.data;
           this.carryDetail = JSON.parse(JSON.stringify(result.data));
           if(projectInfo)  this.projectInfo =  projectInfo;
           if(projectImplementationTeam)  this.projectImplementationTeam = projectImplementationTeam;
           if(projectImplementationShuxing)  this.projectImplementationShuxing =  projectImplementationShuxing;
           if(projectImplementationWbs)  this.projectImplementationWbs = projectImplementationWbs;
           if(projectImplementationImplement)  this.projectImplementationImplement =  projectImplementationImplement;
           if(summaryInfoList)  this.summaryInfoList = summaryInfoList;
           if(projectImplementationSummary)  this.projectImplementationSummary = projectImplementationSummary;

           //已有附件
            if(projectImplementationShuxing){//项目属性认定
              if(projectImplementationShuxing.xmsxrdFileid){
                this.projectImplementationShuxingXmsxrdFileList =[
                  {
                    name:projectImplementationShuxing.xmsxrdFileName,
                    id:projectImplementationShuxing.xmsxrdFileid
                  }
                ]
              }
            }

             if(projectImplementationWbs){//实施阶段WBS及预算申请
              if(projectImplementationWbs.htFileid){
                this.projectImplementationWbsHtFileList =[
                  {
                    name:projectImplementationWbs.htFileName,
                    id:projectImplementationWbs.htFileid
                  }
                ]
              }
              if(projectImplementationWbs.sycsbFileid){
                this.projectImplementationWbsSycsbFileList =[
                  {
                    name:projectImplementationWbs.sycsbFileName,
                    id:projectImplementationWbs.sycsbFileid
                  }
                ]
              }
              if(projectImplementationWbs.wbssqFileid){
                this.projectImplementationWbsWbssqFileList =[
                  {
                    name:projectImplementationWbs.wbssqFileName,
                    id:projectImplementationWbs.wbssqFileid
                  }
                ]
              }
              if(projectImplementationWbs.yssqFileid){
                this.projectImplementationWbsYssqFileList =[
                  {
                    name:projectImplementationWbs.yssqFileName,
                    id:projectImplementationWbs.yssqFileid
                  }
                ]
              }
            }

            if(projectImplementationSummary){//项目总结
              if(projectImplementationSummary.summaryFileid){
                this.projectImplementationSummarySummaryFileList =[
                  {
                    name:projectImplementationSummary.summaryFileName,
                    id:projectImplementationSummary.summaryFileid
                  }
                ]
              }
            }

          
        } else {
          ALERT.error(result.msg)
        }
      })

    },

     //判断模块是否显示 
    showModulesFn(arr,type){
     let newArr =[];
     let flag = true; 
     for(let i = 0;i<arr.length;i++){
       let bol = true;
       let tmmpArr = arr.slice(0,i+1);
       for(let item of arr.slice(0,i+1)){
         if(bol==true&&!!item == false&&flag&&type=='edit'){
           bol = true;
           flag = false;
           this.curEditIndex = i;
         }else{
           bol = bol && item
         }
       }
       if(i == arr.length-1 && flag){
         this.curEditIndex = null;
       }
       newArr[i] = bol
     }
     return newArr
    },

     //取消所有编辑状态
    inactiveAll(refs){
      let refsArr =['pitBlockToggle','pisBlockToggle','piwBlockToggle','piiBlockToggle','silBlockToggle','pisyBlockToggle'];
      refsArr.forEach(element => {
        if(refs!=element &&  this.$refs[element]) {
          this.$refs[element].cancelClick();
        }
      });
      this.curEditIndex = null;
    },
    
    
    //组建实施团队编辑操作相关方法
    projectImplementationTeamEditClick(){
      this.inactiveAll("pitBlockToggle");
      this.projectImplementationTeamEdit = true;
    },
    projectImplementationTeamMouseleaveHandle({showBtn}){
      this.projectImplementationTeamEdit = showBtn;
    },
    projectImplementationTeamCancelClick(){
      this.projectImplementationTeamEdit = false;
      this.$refs.projectImplementationTeam.clearValidate();
      this.projectImplementationTeam = this.carryDetail.projectImplementationTeam ? JSON.parse(JSON.stringify(this.carryDetail.projectImplementationTeam)) : {}
    },
    //组建实施团队保存
    projectImplementationTeamSaveClick(){
      //项目成员
      this.projectImplementationTeam.members = COMMON.changePersonSelectData(this.$refs.projectImplementationTeamMembers);
      this.$set(this.projectImplementationTeam,'projectImplementationTeamMembersStr',COMMON.arrToStr(this.projectImplementationTeam.members,"peopleName"))
      //项目经理
      this.$set(this.projectImplementationTeam,"projectManagerName",COMMON.changePersonSelectData(this.$refs.projectManagerName,false).peopleName)
      this.$set(this.projectImplementationTeam,"projectManager",COMMON.changePersonSelectData(this.$refs.projectManagerName,false).peopleNumber)
      //商务经理
      this.$set(this.projectImplementationTeam,"businessManagerName",COMMON.changePersonSelectData(this.$refs.businessManagerName,false).peopleName)
      this.$set(this.projectImplementationTeam,"businessManager",COMMON.changePersonSelectData(this.$refs.businessManagerName,false).peopleNumber)
      this.$refs.projectImplementationTeam.validate((valid, error) => {
        if (valid) {
          this.projectImplementationTeamLoading = true;
          const {
            projectDate,
            projectManager,
            projectManagerName,
            businessManager,
            businessManagerName,
            members,
          } = this.projectImplementationTeam;
          opr_management.saveprojectImplementationTeam({
            projectid:this.$router.history.current.params.id,
           projectDate,
            projectManager,
            projectManagerName,
            businessManager,
            businessManagerName,
            members,
          }, result => {
            this.projectImplementationTeamLoading = false;
            if (result.code === Constant.RT_SUCCESS) {
              this.projectImplementationTeamEdit = false;
              this.$refs.pitBlockToggle.inactive();
              this.$refs.projectImplementationTeam.clearValidate();
              this.getInitData();
            } else {
              ALERT.error(result.msg)
            }
            
          })
        }
      });
    },

    //项目属性认定编辑操作相关方法
    projectImplementationShuxingEditClick(){
      this.inactiveAll("pisBlockToggle");
      this.projectImplementationShuxingEdit = true;
    },
    projectImplementationShuxingMouseleaveHandle({showBtn}){
      this.projectImplementationShuxingEdit = showBtn;
    },
    projectImplementationShuxingCancelClick(){
      this.projectImplementationShuxingEdit = false
      this.$refs.projectImplementationShuxing.clearValidate();
      this.projectImplementationShuxing = this.carryDetail.projectImplementationShuxing ? JSON.parse(JSON.stringify(this.carryDetail.projectImplementationShuxing)) : {}
    },
    projectImplementationShuxingSaveClick(){
      this.$refs.projectImplementationShuxing.validate((valid, error) => {
        if (valid) {
          this.projectImplementationShuxingLoading = true;
          const {
            xmsxrdFileid,
          } = this.projectImplementationShuxing;
          opr_management.saveprojectImplementationOption({
            projectid:this.$router.history.current.params.id,
            xmsxrdFileid,
          }, result => {
            this.projectImplementationShuxingLoading = false;
            if (result.code === Constant.RT_SUCCESS) {
              this.projectImplementationShuxingEdit = false;
              this.$refs.pisBlockToggle.inactive();
              this.$refs.projectImplementationShuxing.clearValidate();
              this.getInitData();
            } else {
              ALERT.error(result.msg)
            }
            
          })
        }

      })

    },

    //实施阶段WBS及预算申请编辑操作相关方法
    projectImplementationWbsEditClick(){
      this.inactiveAll("piwBlockToggle");
      this.projectImplementationWbsEdit = true;
    },
    projectImplementationWbsMouseleaveHandle({showBtn}){
      this.projectImplementationWbsEdit = showBtn;
    },
    projectImplementationWbsCancelClick(){
      this.projectImplementationWbsEdit = false
      this.$refs.projectImplementationWbs.clearValidate();
      this.projectImplementationWbs = this.carryDetail.projectImplementationWbs ? JSON.parse(JSON.stringify(this.carryDetail.projectImplementationWbs)) : {}
    },
    projectImplementationWbsSaveClick(){
      
      //负责人
      this.$set(this.projectImplementationWbs,"leadingmanName",COMMON.changePersonSelectData(this.$refs.projectImplementationWbsLeadingman,false).peopleName)
      this.$set(this.projectImplementationWbs,"leadingman",COMMON.changePersonSelectData(this.$refs.projectImplementationWbsLeadingman,false).peopleNumber)
      
      this.$refs.projectImplementationWbs.validate((valid, error) => {
        if (valid) {
          this.projectImplementationWbsLoading = true;
          const {
            cbsCode,
            cbsName,
            leadingman,
            leadingmanName,
            budgetType,
            currency,
            depositAmount,
            payStorage,
            transClassification,
            wbssqFileid,
            yssqFileid,
            htFileid,
            sycsbFileid
          } = this.projectImplementationWbs;
          opr_management.saveprojectImplementationWbs({
            projectid:this.$router.history.current.params.id,
            cbsCode,
            cbsName,
            leadingman,
            leadingmanName,
            budgetType,
            currency,
            depositAmount,
            payStorage,
            transClassification,
            wbssqFileid,
            yssqFileid,
            htFileid,
            sycsbFileid
          }, result => {
            this.projectImplementationWbsLoading = false;
            if (result.code === Constant.RT_SUCCESS) {
              this.projectImplementationWbsEdit = false;
              this.$refs.piwBlockToggle.inactive();
              this.$refs.projectImplementationWbs.clearValidate();
              this.getInitData();
            } else {
              ALERT.error(result.msg)
            }
            
          })
        }

      })

    },

    //项目执行 编辑操作相关方法
    //新增
    addImplementListHandle(){
      this.implementListDialogVisible = true;
      this.implementListDialogObj = {
           type:"add",
           index:null
      };
    },
    //弹窗确认
    addImplementListConfirm(){
      this.$refs.implementListForm.validate((valid, error) => {
        if (valid) {
          if(this.implementListDialogObj.type =="add"){//新增
            if(!this.projectImplementationImplement.implementList) this.projectImplementationImplement.implementList = [];
            this.projectImplementationImplement.implementList.push(Object.assign({},
            this.implementListForm,
            {
              add:true,
              projectid:this.$router.history.current.params.id,
            }))
          }else if(this.implementListDialogObj.type =="edit"){//编辑
            this.projectImplementationImplement.implementList[this.implementListDialogObj.index] = Object.assign({},
            this.implementListForm,
            {
              add:true,
            })
          }
          this.implementListDialogVisible = false;
          this.implementListForm = {}
          this.$refs.implementListFormYszs.clearFiles();
          this.implementListFormYszsList = [];
         
        }
      })
    },
    //弹窗取消
    addImplementListCancel(){
      this.implementListDialogVisible = false;
      this.implementListForm = {};
      this.$refs.implementListForm.clearValidate();
      this.$refs.implementListFormYszs.clearFiles();
      this.implementListFormYszsList = [];
    },
    //列表操作按钮点击
    implementListHandleListBtn({btn,row}){
      if(btn==="look"){//查看
         this.implementListDialogVisible = true;
         this.implementListDialogObj = {
           type:"look",
           index:null
         };
         this.implementListForm = row
      }else if(btn==="edit"){//编辑
         this.implementListDialogVisible = true;
         this.implementListDialogObj = {
           type:"edit",
           index:row.index
         };
         this.implementListForm = this.projectImplementationImplement.implementList[row.index]
         if(this.implementListForm.yszs){
           this.$set( this,'implementListFormYszsList',[
              {
                name:this.implementListForm.yszsFileName,
                id:this.implementListForm.yszs
              }
            ])
         }
      }else if(btn==="del"){//删除
          COMMON.confirm({}, () => {
            this.projectImplementationImplement.implementList.splice(row.index,1)
          })
      }else if(btn==="notify_business"){//通知商务经理
          if(row.isddsk-0){//达到收款条件
            opr_management.projectnotifyBusiness({
              projectId:this.$router.history.current.params.id,
            }, result => {
              if (result.code === Constant.RT_SUCCESS) {
                ALERT.success(result.msg)
              } else {
                ALERT.error(result.msg)
              }
            })
          }else{//未达到收款条件
             this.$message.warning('未达到收款条件');
          }
          

      }

    },
    projectImplementationImplementEditClick(){
      this.inactiveAll("piiBlockToggle");
      this.projectImplementationImplementEdit = true;
    },
    projectImplementationImplementMouseleaveHandle({showBtn}){
      this.projectImplementationImplementEdit = showBtn;
    },
    projectImplementationImplementCancelClick(){
      this.projectImplementationImplementEdit = false
      this.$refs.projectImplementationImplement.clearValidate();
      this.projectImplementationImplement = this.carryDetail.projectImplementationImplement ? JSON.parse(JSON.stringify(this.carryDetail.projectImplementationImplement)) : {}
    },
    projectImplementationImplementSaveClick(){
      this.$refs.projectImplementationImplement.validate((valid, error) => {
        if (valid) {
          const {
            projectSummaryRequirement,
            implementList
          } = this.projectImplementationImplement;
          if(!implementList.length){//进展为空
            if(projectSummaryRequirement == 1){//已达成
              return ALERT.warn('项目无任何进展，无法进行项目总结')
            }else{ //未达成
              return ALERT.warn('项目无任何进展，无法进行保存')
            }
          }else{//进展不为空
             if(projectSummaryRequirement == 1){//已达成
                let isSummaryInfo = true;
                for( var item of implementList){
                  let isItemSummaryInfo = item.isddsk == 1 ? true : false;
                  isSummaryInfo = isSummaryInfo && isItemSummaryInfo
                }
                if(!isSummaryInfo){
                 return COMMON.confirm({
                    content:"项目有未收款，是否进入项目总结？"
                  }, () => {
                    this.projectImplementationImplementReq({
                      projectSummaryRequirement,
                      implementList
                    })
                  })
                }
             }
          }
          this.projectImplementationImplementReq({
            projectSummaryRequirement,
            implementList
          })
        }
      })
    },
    //保存项目执行请求
    projectImplementationImplementReq({projectSummaryRequirement,implementList}){
      this.projectImplementationImplementLoading = true;
        opr_management.saveprojectImplementationImplement({
          projectid:this.$router.history.current.params.id,
          projectSummaryRequirement,
          implementList
        }, result => {
          this.projectImplementationImplementLoading = false;
          if (result.code === Constant.RT_SUCCESS) {
            this.projectImplementationImplementEdit = false;
            this.$refs.piiBlockToggle.inactive();
            this.$refs.projectImplementationImplement.clearValidate();
            this.getInitData();
          } else {
            ALERT.error(result.msg)
          }
          
        })
    },

    

    //合同收款 编辑操作相关方法
    //新增
    addSummaryInfoListHandle(){
      this.summaryInfoListDialogVisible = true;
      this.summaryInfoListDialogObj = {
        type:"add",
        index:null
      }
    },
    //弹窗确认
    addSummaryInfoListConfirm(){
      this.$refs.summaryInfoListForm.validate((valid, error) => {
        if (valid) {
          if(this.summaryInfoListDialogObj.type =="add"){//新增
            if(!this.summaryInfoList) this.summaryInfoList = [];
            this.summaryInfoList.push(Object.assign({},
            this.summaryInfoListForm,
            {
              projectid:this.$router.history.current.params.id,
            }))
          }else if(this.summaryInfoListDialogObj.type =="edit"){//编辑
            this.summaryInfoList[this.summaryInfoListDialogObj.index] = this.summaryInfoListForm
          }
          this.summaryInfoListDialogVisible = false;
          this.summaryInfoListForm = {}
          this.$refs.summaryInfoListFormYszs.clearFiles();
          this.$refs.summaryInfoListFormZfsqh.clearFiles();
          this.summaryInfoListFormYszsList = [];
          this.summaryInfoListFormZfsqhList = [];

        }
      })
    },
    //弹窗取消 
    addSummaryInfoListCancel(){
      this.summaryInfoListDialogVisible = false;
      this.summaryInfoListForm = {}
      this.$refs.summaryInfoListForm.clearValidate();
      this.$refs.summaryInfoListFormYszs.clearFiles();
      this.$refs.summaryInfoListFormZfsqh.clearFiles();
      this.summaryInfoListFormYszsList = [];
      this.summaryInfoListFormZfsqhList = [];
    },
    //列表操作按钮点击
    summaryInfoListHandleListBtn({btn,row}){
      if(btn==="look"){//查看
         this.summaryInfoListDialogVisible = true;
         this.summaryInfoListDialogObj = {
           type:"look",
           index:null
         };
         this.summaryInfoListForm = row
      }else if(btn==="edit"){//编辑
         this.summaryInfoListDialogVisible = true;
         this.summaryInfoListDialogObj = {
           type:"edit",
           index:row.index
         };
         this.summaryInfoListForm = this.summaryInfoList[row.index]
         if(this.summaryInfoListForm.yszs){
           this.$set( this,'summaryInfoListFormYszsList',[
              {
                name:this.summaryInfoListForm.yszsFileName,
                id:this.summaryInfoListForm.yszs
              }
            ])
         }
         if(this.summaryInfoListForm.zfsqh){
           this.$set( this,'summaryInfoListFormZfsqhList',[
              {
                name:this.summaryInfoListForm.zfsqhFileName,
                id:this.summaryInfoListForm.zfsqh
              }
            ])
         }
      }else if(btn==="del"){//删除
          COMMON.confirm({}, () => {
            this.summaryInfoList.splice(row.index,1)
          })
      }
    },
    summaryInfoListEditClick(){
      this.inactiveAll("silBlockToggle");
      this.summaryInfoListEdit = true;
    },
    summaryInfoListMouseleaveHandle({showBtn}){
      this.summaryInfoListEdit = showBtn;
    },
    summaryInfoListCancelClick(){
      this.summaryInfoListEdit = false
      // this.$refs.summaryInfoList.clearValidate();
      this.summaryInfoList = this.carryDetail.summaryInfoList ? JSON.parse(JSON.stringify(this.carryDetail.summaryInfoList)) : []
    },
    summaryInfoListSaveClick(){
      // this.$refs.summaryInfoList.validate((valid, error) => {
      // if (valid) {
          const summaryInfoList = this.summaryInfoList;
          if(!summaryInfoList.length){//收款项为空
             return ALERT.warn('项目无任何收款项，无法进行保存')
          }else{//收款项不为空
            this.summaryInfoListLoading = true;
            opr_management.saveprojectImplementationSummaryInfo(summaryInfoList, result => {
              this.summaryInfoListLoading = false;
              if (result.code === Constant.RT_SUCCESS) {
                this.summaryInfoListEdit = false;
                this.$refs.silBlockToggle.inactive();
                // this.$refs.summaryInfoList.clearValidate();
                this.getInitData();
              } else {
                ALERT.error(result.msg)
              }
              
            })
          } 
         
        // }

      // })

    },
    //计算总计
    getSummaries(param){
        const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总计';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))&&(index==2||index==4||index==9)) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
          } else {
            sums[index] = ' ';
          }
        });

        return sums;

    },

    //项目总结 编辑操作相关方法
    projectImplementationSummaryEditClick(){
      this.inactiveAll("pisyBlockToggle");
      this.projectImplementationSummaryEdit = true;
    },
    projectImplementationSummaryMouseleaveHandle({showBtn}){
      this.projectImplementationSummaryEdit = showBtn;
    },
    projectImplementationSummaryCancelClick(){
      this.projectImplementationSummaryEdit = false
      this.$refs.projectImplementationSummary.clearValidate();
      this.projectImplementationSummary = this.carryDetail.projectImplementationSummary ? JSON.parse(JSON.stringify(this.carryDetail.projectImplementationSummary)) : {}
    },
    projectImplementationSummarySaveClick(){
      this.$refs.projectImplementationSummary.validate((valid, error) => {
        if (valid) {
          this.projectImplementationWbsLoading = true;
          const {
           summary,
           summaryFileid
          } = this.projectImplementationSummary;
          opr_management.saveprojectImplementationSummary({
            projectid:this.$router.history.current.params.id,
           summary,
           summaryFileid,
          }, result => {
            this.projectImplementationSummaryLoading = false;
            if (result.code === Constant.RT_SUCCESS) {
              this.projectImplementationSummaryEdit = false;
              this.$refs.pisyBlockToggle.inactive();
              this.$refs.projectImplementationSummary.clearValidate();
              this.getInitData();
            } else {
              ALERT.error(result.msg)
            }
            
          })
        }

      })

    },

    

  },
}
</script>

<style lang="scss">
.carry-detail{
  .el-table__header,
  .el-table__body,
  .el-table__footer{
      width: 100% !important;
  }
  .el-form-item__content>span:empty:before{
    content:"--"
  }
  .form-input{
    width: 80% !important;
  }
  .table{
    margin-bottom: 20px;
  }
  .dialog{
    .el-select.el-select{
      width: 100%;
    }
    .el-input.el-input{
      width: 60%;
    }
  }

  

}
</style>
